package com.innovation.chengzhangriji.ui.widget;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.FrameLayout;

import com.innovation.chengzhangriji.R;

public abstract class TimelineViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener {

    public interface OnLongClickTimelineListener {
        void onLongClickTimeline(TimelineViewHolder holder);
    }

    private Context mContext;

    private TimelineView mTimeline;

    private OnLongClickTimelineListener mOnLongClickTimelineListener;

    public TimelineViewHolder(Context context, View itemView) {
        super(itemView);
        mContext = context;
        mTimeline = (TimelineView) itemView.findViewById(R.id.timeline);
        mTimeline.getContent().setOnLongClickListener(this);
    }

    @Override
    public boolean onLongClick(View v) {
        if (mOnLongClickTimelineListener == null) {
            return false;
        }
        if (v.getId() == R.id.content) {
            mOnLongClickTimelineListener.onLongClickTimeline(this);
            return true;
        }
        return false;
    }

    public void setOnLongClickTimelineListener(OnLongClickTimelineListener onLongClickTimelineListener) {
        mOnLongClickTimelineListener = onLongClickTimelineListener;
    }

    public final Context getContext() {
        return mContext;
    }

    public FrameLayout getContent() {
        return mTimeline.getContent();
    }

    public void setDate(String date) {
        mTimeline.setDate(date);
    }

    public void setCount(String count) {
        mTimeline.setCount(count);
    }

    public void setRole(String role) {
        mTimeline.setRole(role);
    }

    public void setTime(String time) {
        mTimeline.setTime(time);
    }

    public void setDateVisibility(boolean show, boolean top) {
        mTimeline.setDateVisibility(show, top);
    }

    public void setTimeVisibility(boolean show) {
        mTimeline.setTimeVisibility(show);
    }

    public final int getX() {
        return mTimeline.getContent().getWidth()/2;
    }

    public final int getY() {
        return mTimeline.getTimelineY();
    }

}
